package com.test.blogsystem.Controller;


import com.test.blogsystem.Pojo.Require.UpdateBlogInfo;
import com.test.blogsystem.Pojo.Response.BlogAddResponse;
import com.test.blogsystem.Pojo.Response.BlogInfoResponse;
import com.test.blogsystem.Service.BlogService;
import com.test.blogsystem.Service.Impl.BlogServiceImpl;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList() {
        return blogService.getList();
    }

    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@Nonnull Integer blogId){
        return blogService.getBlogDetail(blogId);
    }

    @RequestMapping("/add")
    public boolean add(@RequestBody @Validated BlogAddResponse blogAddResponse){
        return blogService.addBlog(blogAddResponse);
    }

    @RequestMapping("/update")
    public boolean updateBlog(@RequestBody @Validated UpdateBlogInfo updateBlogInfo){
        log.info("updateBlogInfo为: {}",updateBlogInfo);
        return blogService.updateBlogInfo(updateBlogInfo);
    }

    @RequestMapping("/delete")
    public boolean deleteBlog(Integer blogId){
        log.info("blogId为：" + blogId);
        return blogService.deleteBlog(blogId);
    }
}
